package com.atguigu.gmall.all.controller;

import com.atguigu.gmall.activity.client.SeckillGoodsFeignClient;
import com.atguigu.gmall.model.activity.SeckillGoods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

/**
 * @author ：MJS
 * @date ：Created in 2021/5/31  11:11
 * @description：TODO
 * 秒杀商品页面
 * 列表
 * 详情
 * 抢购
 */
@Controller
public class SeckillGoodsController {
    @Autowired
    private SeckillGoodsFeignClient seckillGoodsFeignClient;
    //列表页面
    @GetMapping("/index")
    public String index(Model model){
        List<SeckillGoods> list = seckillGoodsFeignClient.list();
        model.addAttribute("list",list);
        return "seckill/index";
    }
    //秒杀详情页面
    @GetMapping("/seckill/{skuId}.html")
    public String seckillDetail(@PathVariable Long skuId,Model model){
        SeckillGoods seckillGoods=seckillGoodsFeignClient.getSeckillGoods(skuId);
        model.addAttribute("item",seckillGoods);
        return "seckill/item";
    }
    //去抢购页面
    @GetMapping("/seckill/queue.html")
    public String seckillqueue(Long skuId, String skuIdStr, Model model){
        model.addAttribute("skuId",skuId);
        model.addAttribute("skuIdStr",skuIdStr);
        return "seckill/queue";
    }
}
